
load("js/cib_mobile/Barrett.js")
load("js/cib_mobile/BigInt.js")
load("js/cib_mobile/RSA.js")

var currecy = "";// 信用卡的币种
var cardNum = 1;
var date ="";//信用卡的账单日
// private Map<String, Object> context = new HashMap<>();
var open_time = "";//借记卡的开卡时间
var currency_type = "";//借记卡的币种
var  depoitSdf = new SimpleDateFormat("yyyy-MM-dd");//借记卡
var  creditSdf = new SimpleDateFormat("YYYY-MM");//信用卡
var  last_payment = new BigDecimal("0");//信用卡的上期还款金额
var last_balance = new BigDecimal("0");//信用卡的上期应还总额
var urls = {
    USER_AGENT : "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Mobile Safari/537.36",
    ACCEPT:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"


}
var creditList = new ArrayList();

var v4_cib_mobile_credit_java_funcs ={
    checkProxyAvailable : function(){ return true },
    checkTargetWebsiteAvailable : function(){ return true },
    checkControlAvailable : function () { return true },
    login:function(){
        var cardNo = getLoginParams(context)[0];//卡号
        var certNo = getLoginParams(context)[1];//身份证
        var passWord = context.get(Constants.LUA_TASK_TOKEN);

        //请求公钥
        var param = new HashMap();
        param.put("menu", "0100000020");
        var indexHtml = RequestUtil.post("https://3g.cib.com.cn/app/80820.html", param, getHttpPostTwo());
        storeDataToFile(context, indexHtml, "indexHtml.html");
        var first = indexHtml.indexOf("publicKey = ");
        var publicKeyStr = indexHtml.substring(first + "publicKey = ".length, first + "publicKey = ".length + 258);
        publicKeyStr = publicKeyStr.replaceAll("\"", "").replaceAll("\"", "");
        if(publicKeyStr.length() !== 256){
            publicKeyStr = "";
        }
        logger.info("任务【 {} 】公钥【 {} 】",context.get(LUA_TASK_KEY), publicKeyStr);

        //加密密码
        var passWordEncrypt = hsRSAEncrypt(passWord,publicKeyStr);
        logger.info("任务【 {} 】密文【 {} 】",context.get(LUA_TASK_KEY), passWordEncrypt);


        param.clear();
        //登录并返回结果
        var secendUrl = "https://3g.cib.com.cn/app/00002.html";
        param.put("flowsn", "402");
        param.put("hsm_pwd", passWordEncrypt);
        param.put("select_flag", "0");
        param.put("loginname", cardNo);
        param.put("req_zjhm", certNo);
        param.put("pwd", passWordEncrypt);
        var loginResultHtml = RequestUtil.post(secendUrl,param,getHttpPostTwo());
        storeDataToFile(context, loginResultHtml, "loginResult.html");

        var isLoginCorrectFunc = function(loginResultHtml) {
            if(StringUtils.isBlank(loginResultHtml)) {
                return false;
            }
            if(loginResultHtml.contains("Proxy Error")){
                return false;
            }
            var doc = Jsoup.parse(loginResultHtml);

            if(equals(doc.select("#cvv2").attr("placeholder"), "卡片签名栏末三位")){
                return false

            }else if(equals("请按以下流程激活信用卡：",doc.select(".words").text())){
                return false
            }

            var checkText = doc.select("h2.mk-title").text()
            logger.info("任务【 {} 】待检查文本: '{}'", context.get(LUA_TASK_KEY), checkText)
            return StringUtils.isNotBlank(checkText) && checkText.contains("尊敬的")
        }

        var getLoginErrorMsgFunc = function(loginResultHtml) {
            if(StringUtils.isBlank(loginResultHtml)) {
                return "登录超时";
            }
            if(loginResultHtml.contains("Proxy Error")){
                return "代理IP异常";
            }

            var doc = Jsoup.parse(loginResultHtml);

            var checkText = doc.select("#cvv2").attr("placeholder")
            logger.info("任务【 {} 】待检查文本: '{}'", context.get(LUA_TASK_KEY), checkText)

            var  activateCard = doc.select(".words").text();
            logger.info("任务【 {} 】激活的卡: '{}'", context.get(LUA_TASK_KEY), activateCard)

            if(equals(checkText, "请输入签名栏末三位")){
                return "请输入卡片签名栏末三位"
            }else if(equals("请按以下流程激活信用卡：",activateCard)){
                return "请按以下流程激活信用卡"
            }

            var errorMsg = doc.select("p.result-describe").text();
            logger.info("任务【 {} 】错误信息: {}", context.get(LUA_TASK_KEY), errorMsg)
            if(errorMsg.contains("未配置错误信息")){
                return "未配置错误信息"
            }
            return errorMsg
        }

        assertTrueOrThrowException(loginResultHtml, isLoginCorrectFunc, getLoginErrorMsgFunc)
        logger.info("任务【 {} 】登录成功", context.get(LUA_TASK_KEY))
    },
    crawl :function() {
        var param = new HashMap();
        // 声明存储对象
        var creditCardAllData = new CreditCardAllData();
        if ( getLoginParams(context)[0].length() == 16) {// 信用卡
            creditCrawl(creditCardAllData, param);
        } else {// 借记卡
            depCrawl(creditCardAllData, param);
        }
        creditList.add(creditCardAllData);
        logger.info(creditList)
        context.put(Constants.CREDIT_DATA, creditList);
    },
    exitLogin :function () {}
}

/**
 * 给pwd加密
 * @type {string}
 */
function hsRSAEncrypt(str,publicKey){
    if(publicKey=="") return str;
    setMaxDigits(130);
    var key = new RSAKeyPair("10001" , "" , publicKey);
    var enStr = encryptedString(key,str);
    return enStr;
}

/**
 * 信用卡的账户信息
 *
 * @param creditCardAllData
 * @throws Exception
 */
function  getBasicNeedInfo( creditCardAllData, param,  cardNum)  {
    logger.info("{},开始抓取信用卡账户信息",context.get(Constants.LUA_TASK_KEY));
    try {
        creditCardAllData.setBankName("兴业银行");
        creditCardAllData.setCardId(UUID.randomUUID().toString());// 银行卡id
        creditCardAllData.setCardType("信用卡");//
        creditCardAllData.setOpenBank("");
        var secendUrl = "https://3g.cib.com.cn/app/80820.html";
        param.clear();
        param.put("flowsn", "50");
        param.put("secmenu", "0200000394");
        var baseInfoHtml = RequestUtil.post(secendUrl,param,getHttpPostCreditOne());
        storeDataToFile(context,baseInfoHtml, cardNum + "_card.html");
        var doc = Jsoup.parse(baseInfoHtml);
        var table = doc.getElementsByClass("MBcontent1").get(0);
        var trs = table.select("tr");
        // 用户名
        var userName = "";
        // 可用信用额度
        var availableLimit = "";
        // 信用额度
        var creditLimit = "";
        // 可用取现额度
        var enChashMentImprest = "";
        // 取现额度
        var cashLimit = "";
        // 卡号
        var fullCardNum = doc.select("#rmbxx > table > tbody > tr:nth-child(2) > td:nth-child(3)").text().trim().replaceAll("\\s*","");
        if (trs.size() == 30) {// li
            // 用户名
            userName = doc.select("#rmbxx > table > tbody > tr:nth-child(3) > td:nth-child(3)").get(0).text();
            // 可用信用额度 #rmbxx > table > tbody > tr:nth-child(8) > td:nth-child(3)
            availableLimit = doc.select("#rmbxx > table > tbody > tr:nth-child(8) > td:nth-child(3)").get(0).text();
            // 信用额度#rmbxx > table > tbody > tr:nth-child(7) > td:nth-child(3)
            creditLimit = doc.select("#rmbxx > table > tbody > tr:nth-child(7) > td:nth-child(3)").get(0).text();
            // 可用取现额度#rmbxx > table > tbody > tr:nth-child(10) > td:nth-child(3)
            enChashMentImprest = doc.select("#rmbxx > table > tbody > tr:nth-child(10) > td:nth-child(3)").get(0)
                .text();
            // 取现额度#rmbxx > table > tbody > tr:nth-child(9) > td:nth-child(3)
            cashLimit = doc.select("#rmbxx > table > tbody > tr:nth-child(9) > td:nth-child(3)").get(0).text();
        } else if (trs.size() == 31) {
            // 用户名
            userName = doc.select("#rmbxx > table > tbody > tr:nth-child(4) > td:nth-child(3)").get(0).text();
            // 可用信用额度
            availableLimit = doc.select("#rmbxx > table > tbody > tr:nth-child(9) > td:nth-child(3)").get(0).text();
            // 信用额度
            creditLimit = doc.select("#rmbxx > table > tbody > tr:nth-child(8) > td:nth-child(3)").get(0).text();
            // 可用取现额度
            enChashMentImprest = doc.select("#rmbxx > table > tbody > tr:nth-child(11) > td:nth-child(3)").get(0)
                .text();
            // 取现额度
            cashLimit = doc.select("#rmbxx > table > tbody > tr:nth-child(10) > td:nth-child(3)").get(0).text();
        }
        creditCardAllData.setFullCardNum(fullCardNum);// 卡号
        creditCardAllData.setCardNum(fullCardNum.substring((fullCardNum.length() - 4), (fullCardNum.length())));// 卡号后四位
        creditCardAllData.setNameOnCard(userName);
        creditCardAllData.setCreditLimit(new BigDecimal(creditLimit));
        creditCardAllData.setBalance(new BigDecimal(availableLimit));
        creditCardAllData.setCashBalance(new BigDecimal(enChashMentImprest));
        creditCardAllData.setCashLimit(new BigDecimal(cashLimit));
    } catch (e) {
        logger.error("{},信用卡账户信息抓取异常{}",context.get(Constants.LUA_TASK_KEY),e);
        statCaughtException(context, e);
    }
}

/**
 * 借记卡抓取
 * @param creditCardAllData
 * @param param
 * @throws Exception
 */
function  depCrawl(creditCardAllData, param) {
    logger.info("{},借记卡抓取开始",context.get(Constants.LUA_TASK_KEY));
    //卡的数量
    var cardURL = "https://3g.cib.com.cn/app/80820.html";
    param.clear();
    param.put("menu", "0100000021");
    param.put("divtype", "");
    RequestUtil.post(cardURL,param,getHttpPostOne());
    param.clear();
    param.put("flowsn", "50");
    param.put("secmenu", "0200000316");
    var cardCountHtml =  RequestUtil.post(cardURL,param,getHttpPostOne());
    storeDataToFile(context,cardCountHtml, "cardList.html");
    var cardCountDoc = Jsoup.parse(cardCountHtml);
    var counts = cardCountDoc.select(".m-card-wrap li");

    for(var cardNum = 1 ; cardNum <= counts.size(); cardNum ++){
        //基本信息
        parseBaseInfo(creditCardAllData,param,cardNum);

        var  creditCardTimeDeposits = new ArrayList();
        //存款
        creditCardAllData.setDeposits(creditCardTimeDeposits);

        var billAllDatas = new ArrayList();
        //存款信息
        creditCardAllData.setBills(billAllDatas);

        //账单流水
        billInfoDetail(creditCardAllData,param,cardNum);

        //定期
        saveDeposits(creditCardAllData,param,cardNum);
    }
}

/**
 * 借记卡的存储
 * @param creditCardAllData
 * @param param
 * @param cardNum
 * @throws IOException
 * @throws Exception
 */
function saveDeposits(creditCardAllData,  param, cardNum) {
    logger.info("{},开始抓取借记卡定期",context.get(Constants.LUA_TASK_KEY));
    try {
        var  deposit;
        /**
         * 活期
         */
        var huoOne = "https://3g.cib.com.cn/app/80820.html";
        param.clear();
        param.put("menu", "0100000020");
        param.put("divtype", "");
        RequestUtil.post(huoOne,param,getHttpPostOne());


        var huoTwo = "https://3g.cib.com.cn/app/10020.html";
        param.clear();
        param.put("flowsn", "201");
        param.put("listcardno", "0");
        param.put("listno", "0");
        var huoTwoHtml =  RequestUtil.post(huoTwo,param,getHttpPostOne());

        storeDataToFile(context,huoTwoHtml, cardNum + "_card_cunchu.html");
        var huoTwoDoc = Jsoup.parse(huoTwoHtml);
        var tables = huoTwoDoc.select("table");
        var balance = "";
        var deposit_date = "";
        var due_date ="";
        var deposit_type ="";
        for(var i = 0;i < tables.size()-1; i++){
            deposit = new CreditCardTimeDeposit();
            var text = huoTwoDoc.select("body > div.content > form > table:nth-child("+(4+i)+") > tbody > tr:nth-child(1) > td:nth-child(1)").text().trim();
            if(equals(text,"人民币活期存款")){
                balance = huoTwoDoc
                    .select("body > div.content > form > table:nth-child(4) > tbody > tr:nth-child(2) > td:nth-child(1)")
                    .text().replaceAll("账户余额：", "").replaceAll(",", "");
                var huoqiURL = "https://3g.cib.com.cn/app/10020.html";
                param.clear();
                param.put("flowsn", "250");
                param.put("mxlistno", "001");
                param.put("cardindex", "0");
                var huoqiBaseHtml = RequestUtil.post(huoqiURL,param,getHttpPostThree());
                storeDataToFile(context,huoqiBaseHtml, cardNum +"_card_cunchu_huoqi.html");
                var huoqiBaseDoc = Jsoup.parse(huoqiBaseHtml);
                // 定期类型
                deposit_type = huoqiBaseDoc
                    .select("body > div.content > div.product-introduce > div:nth-child(1) > div:nth-child(2) > span")
                    .text().trim();
                // 定期金额
                deposit.setBalance(new BigDecimal(balance));
                // 定期类型
                deposit.setDepositType(deposit_type);
                // 定期币种
                deposit.setCurrencyType("CNY");
                // 计息时间
                // deposit.setDepositDate(yyyy_MM_dd_PARSER.parse(deposit_date));
                // 到期时间
                // deposit.setDueDate(yyyy_MM_dd_PARSER.parse(due_date));
                // 存期
                deposit.setPeriod(null);
                // 存期单位
                deposit.setPeriodUnit("");

            }else if (equals(text,"人民币定期存款")){
                var depURL="https://3g.cib.com.cn/app/10000.html";
                param.clear();
                param.put("flowsn", "50");
                param.put("secmenu", "0300001030");
                RequestUtil.post(depURL,param,getHttpPostOne());
                var depDetailsURL ="https://3g.cib.com.cn/app/20021.html";
                param.clear();
                param.put("flowsn", "100");
                param.put("listno", "0");
                param.put("beginNo", "");
                var depDetailsHtml = RequestUtil.post(depDetailsURL,param,getHttpPostCreditTwo());
                storeDataToFile(context,depDetailsHtml, cardNum + "_card_cunchu_dingqi.html");

                var depDetailsDoc = Jsoup.parse(depDetailsHtml);
                //定期类型
                deposit_type = depDetailsDoc.select("body > div.content > div.form-box.mat5 > ul > li:nth-child(2) > strong").text();
                //金额
                balance = depDetailsDoc.select("body > div.content > div.form-box.mat5 > ul > li:nth-child(3) > strong").text().replaceAll(",", "");
                //计息时间
                deposit_date = depDetailsDoc.select("body > div.content > div.form-box.mat5 > ul > li:nth-child(7) > strong").text().replaceAll("/", "-");
                //到期时间
                due_date = depDetailsDoc.select("body > div.content > div.form-box.mat5 > ul > li:nth-child(8) > strong").text().replaceAll("/", "-");
                //存期时间   三个月
                var period = depDetailsDoc.select("body > div.content > div.form-box.mat5 > ul > li:nth-child(5) > strong").text();
                //利率
                if (equals(period,"三个月")) {
                    deposit.setInterest(new BigDecimal("0.014"));
                } else if (equals(period,"六个月")) {
                    deposit.setInterest(new BigDecimal("0.0165"));
                } else if (equals(period,"一年")) {
                    deposit.setInterest(new BigDecimal("0.0195"));
                } else if (equals(period,"二年")) {
                    deposit.setInterest(new BigDecimal("0.027"));
                } else if (equals(period,"三年")) {
                    deposit.setInterest(new BigDecimal("0.032"));
                } else if (equals(period,"五年")) {
                    deposit.setInterest(new BigDecimal("0.032"));
                }

                // 存期单位
                var period_unit = period.contains("月") ? "MONTH": "YEAR";

                period = period.substring(0, 1);
                if(equals(period,"一")){
                    period ="1";
                }else if(equals(period,"二")){
                    period ="2";
                }else if(equals(period,"三")){
                    period ="3";
                }else if(equals(period,"五")){
                    period ="5";
                }else if(equals(period,"六")){
                    period ="6";
                }
                //定期金额
                deposit.setBalance(new BigDecimal(balance));
                //定期类型
                deposit.setDepositType(deposit_type);
                //定期币种
                deposit.setCurrencyType("CNY");
                //计息时间
                deposit.setDepositDate(yyyy_MM_dd_PARSER.parse(deposit_date));
                //到期时间
                deposit.setDueDate(yyyy_MM_dd_PARSER.parse(due_date));
                //存期
                deposit.setPeriod(Integer.parseInt(period));
                //存期单位
                deposit.setPeriodUnit(period_unit);
            }
            //将CreditCardTimeDeposit添加到集合中
            creditCardAllData.getDeposits().add(deposit);
        }
    } catch (e) {
        logger.error("{},借记卡存储抓取异常:{}",context.get(Constants.LUA_TASK_KEY),e);
        statCaughtException(context, e);
    }
}
/**
 * 借记卡的账单流水
 * @param creditCardAllData
 * @param param
 * @param cardNum
 * @throws Exception
 */
function billInfoDetail( creditCardAllData,  param, cardNum) {
    var monthFirstDay = getMonthFirstDay();
    var monthLastDay = getMonthLastDay();
    for(var i = 0 ; i < 12; i ++){
        if( open_time !== "" && null !== open_time){
            if (depoitSdf.parse(open_time).after(depoitSdf.parse(monthFirstDay.get(i)))
                && depoitSdf.parse(open_time).after(depoitSdf.parse(monthLastDay.get(i)))) {
                break;
            }
        }
        //每月的第一天
        var firstDay = monthFirstDay.get(i);
        //每月的最后一天
        var lastDay = monthLastDay.get(i);

        var billAllData = new BillAllData();
        billAllData.setBillId(UUID.randomUUID().toString());
        billAllData.setBillType("");
        billAllData.setBankName("兴业银行");
        billAllData.setBillMonth(firstDay.substring(0, 7));//格式:yyyy-MM   2017-06
        billAllData.setBillDate(yyyy_MM_dd_PARSER.parse(firstDay));
        billAllData.setNewBalance(null);
        billAllData.setUsdNewBalance(null);
        billAllData.setMinPayment(null);
        billAllData.setUsdMinPayment(null);
        billAllData.setLastBalance(null);
        billAllData.setUsdLastBalance(null);
        billAllData.setLastPayment(null);
        billAllData.setUsdLastPayment(null);
        billAllData.setNewCharges(null);
        billAllData.setUsdNewCharges(null);
        billAllData.setInterest(null);
        billAllData.setUsdInterest(null);
        billAllData.setUsdInterest(null);
        billAllData.setCreditLimit(null);
        billAllData.setUsdCreditLimit(null);
        billAllData.setCashLimit(null);
        billAllData.setUsdCashLimit(null);
        //账单详情
        var expenses = new ArrayList();
        billAllData.setShoppingSheets(expenses);
        firstDay = firstDay.replaceAll("-", "");
        lastDay = lastDay.replaceAll("-", "");
        saveBillsDetail(creditCardAllData, billAllData, firstDay, lastDay, param,cardNum,i);
        creditCardAllData.getBills().add(billAllData);
    }
}

/**
 * 借记卡的账单流水
 * @param creditCardAllData
 * @param billAllData
 * @param firstDay
 * @param lastDay
 * @param param
 * @param cardNum2
 * @param i
 */
function saveBillsDetail( creditCardAllData,  billAllData,  firstDay, lastDay, param,   cardNum2,  i) {
    logger.info("{},开始抓取借记卡{}账单",context.get(Constants.LUA_TASK_KEY),firstDay);
    try {
        var baseURL="https://3g.cib.com.cn/app/80820.html";
        param.put("flowsn", "50");
        param.put("secmenu", "0200000300");
        RequestUtil.post(baseURL,param,getHttpPostOne());
        var billsDetailTwoURL = "https://3g.cib.com.cn/app/10040.html";
        param.clear();
        param.put("flowsn", "4");
        param.put("listcardno", "0");
        param.put("listno", "0");
        RequestUtil.post(billsDetailTwoURL,param,getHttpPostFour());
        param.clear();
        param.put("flowsn", "15");
        param.put("xxh", "001");
        param.put("begindate", firstDay);
        param.put("enddate",lastDay);
        param.put("qrytype", "1");
        var billsDetailThreeHtml = RequestUtil.post(billsDetailTwoURL,param,getHttpPostFour());
        storeDataToFile(context,billsDetailThreeHtml, cardNum + "_bill_" + firstDay + ".html");
        /**
         * 判断有没有
         */
        if(billsDetailThreeHtml.contains("对不起，找不到符合条件的交易明细。")){
            return;
        }

        var billsDetailThreeDoc = Jsoup.parse(billsDetailThreeHtml);

        var  sumPage = billsDetailThreeDoc.select("body > div.content > div.mat10 > form:nth-child(3) > p > span > em").text().replaceAll("\\[", "").replaceAll("\\]", "");
        var sumP = sumPage.split("/");

        var billsDetailThreeForm = billsDetailThreeDoc.select("body > div.content > div.mat10 > form:nth-child(1)");
        var children = billsDetailThreeForm.get(0).children();
        var order = 0;
        for(var i1 = 2 ; i1 < children.size();i1++){
            var expense = new Expense();
            param.clear();
            param.put("flowsn", "200");
            param.put("listno", (i1-2)+"");
            var billsDetailFour = RequestUtil.post(billsDetailTwoURL,param,getHttpPostOne());
            storeDataToFile(context,billsDetailFour, cardNum +"_bill_shopping_sheets_"+ (i1-1)+".html");
            var billsDetailFourDoc = Jsoup.parse(billsDetailFour);

            //记账时间
            var post_date = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(3) > div:nth-child(2) > span").text().trim().replaceAll("/", "-");

            //交易时间
            var trans_date = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(3) > div:nth-child(1) > span").text().trim().replaceAll("/", "-");
            //交易摘要
            var  description = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(2) > div:nth-child(1) > span").text().trim();

            //交易金额
            var amount_moneyText = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(1) > div > p").text().trim();
            var amount_money = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(1) > div > span").text().trim().replaceAll(",", "");
            if(amount_moneyText.contains("收入")){
                amount_money = "-" + amount_money ;
                // 消费类型
                expense.setCategory(CategoryUtil.getDebitCategory(description, amount_money));
            }else if (amount_moneyText.contains("支出")){
                amount_money = "+" + amount_money ;
                // 消费类型
                expense.setCategory(CategoryUtil.getDebitCategory(description, amount_money));
            }

            //账户余额
            var balance = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(2) > div:nth-child(2) > span").text().trim().replaceAll(",", "");

            //对方信息   包括对方持卡人 和对方卡号      (步延伟5218991349688785)
            var  name_on_opposite_card = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(4) > div > span").text().trim();
            var p = Pattern.compile("([\u4e00-\u9fa5]+)");
            var m = p.matcher(name_on_opposite_card);
            var sb = new StringBuffer("");
            while (m.find()) {
                sb.append(URLDecoder.decode(m.group(1),"UTF-8"));
            }

            //对方卡号
            var  opposite_card_no = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(4) > div > span > span").text().trim();

            //对方银行
            var  opposite_bank = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(5) > div > span").text().trim();

            //备注
            var remark = billsDetailFourDoc.select(" body > div.content > div.product-introduce > div:nth-child(6) > div > span").text().trim();

            // 消费id
            expense.setId(UUID.randomUUID().toString());
            // 卡号末四位
            expense.setCardNum(creditCardAllData.getCardNum());
            // 记账日期
            expense.setPostDate(yyyy_MM_dd_PARSER.parse(post_date));

            // 排序
            expense.setOrderIndex(++order);
            // 交易时间
            expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(trans_date));
            // 币种
            expense.setCurrencyType("CNY");
            // 消费金额
            expense.setAmountMoney(new BigDecimal(amount_money));
            // 余额
            expense.setBalance(new BigDecimal(balance));
            // 交易地点
            expense.setTransAddr("");
            // 交易方式
            expense.setTransMethod("");
            // 交易通道
            expense.setTransChannel("");
            // 描述
            expense.setDescription(description);
            // 备注
            expense.setRemark(remark);
            // 对方卡号
            expense.setOppositeCardNo(opposite_card_no);
            // 对方银行
            expense.setOppositeBank(opposite_bank);
            // 对方户名
            expense.setNameOnOppositeCard(sb.toString());

            billAllData.getShoppingSheets().add(expense);
        }

        if(sumPage !== ""){
            //分页
            for(var currentPage = 2 ; currentPage <=Integer.parseInt(sumP[1]); currentPage ++){
                param.clear();
                param.put("beginNo",  (currentPage - 1) + "1");
                param.put("flowsn", "75");
                var billsDetailsNextPageHtml =RequestUtil.post(billsDetailTwoURL,param,getHttpPostFour());
                storeDataToFile(context,billsDetailsNextPageHtml, cardNum + "_bill_shopping_sheets_"+ currentPage+ ".html");
                var billsDetailsNextPageDoc = Jsoup.parse(billsDetailsNextPageHtml);
                var billsDetailsNextPage = billsDetailsNextPageDoc.select("body > div.content > div.mat10 > form:nth-child(1)");
                var childs = billsDetailsNextPage.get(0).children();

                for(var i1 = 2 ; i1 < childs.size();i1++){

                    var expense = new Expense();
                    param.clear();
                    param.put("flowsn", "200");
                    param.put("listno", (currentPage-1)+""+(i1-2));
                    var billsDetailFour = RequestUtil.post(billsDetailTwoURL,param,getHttpPostOne());
                    storeDataToFile(context,billsDetailFour, cardNum + "_bill_shopping_sheets_" + ((currentPage-1)+""+(i1-1)) +".html");
                    var billsDetailFourDoc = Jsoup.parse(billsDetailFour);
                    //记账时间
                    var post_date = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(3) > div:nth-child(2) > span").text().trim().replaceAll("/", "-");
                    //交易时间
                    var trans_date = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(3) > div:nth-child(1) > span").text().trim().replaceAll("/", "-");
                    //交易摘要
                    var  description = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(2) > div:nth-child(1) > span").text().trim();

                    //交易金额
                    var amount_moneyText = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(1) > div > p").text().trim();
                    var amount_money = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(1) > div > span").text().trim().replaceAll(",", "");
                    if(amount_moneyText.contains("收入")){
                        amount_money = "-" + amount_money ;
                        // 消费类型
                        expense.setCategory(CategoryUtil.getDebitCategory(description, amount_money));
                    }else if (amount_moneyText.contains("支出")){
                        amount_money = "+" + amount_money ;
                        // 消费类型
                        expense.setCategory(CategoryUtil.getDebitCategory(description, amount_money));
                    }

                    //账户余额
                    var balance = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(2) > div:nth-child(2) > span").text().trim().replaceAll(",", "");
                    //对方信息   包括对方持卡人 和对方卡号      (步延伟5218991349688785)
                    var  name_on_opposite_card = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(4) > div > span").text().trim();
                    var p = Pattern.compile("([\u4e00-\u9fa5]+)");
                    var m = p.matcher(name_on_opposite_card);
                    var sb = new StringBuffer("");
                    while (m.find()) {
                        sb.append(URLDecoder.decode(m.group(1), "UTF-8"));
                    }
                    //对方卡号
                    var  opposite_card_no = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(4) > div > span > span").text().trim();

                    //对方银行
                    var  opposite_bank = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(5) > div > span").text().trim();

                    //备注
                    var remark = billsDetailFourDoc.select("body > div.content > div.product-introduce > div:nth-child(6) > div > span").text().trim();

                    // 消费id
                    expense.setId(UUID.randomUUID().toString());
                    // 卡号末四位
                    expense.setCardNum(creditCardAllData.getCardNum());
                    // 记账日期
                    expense.setPostDate(yyyy_MM_dd_PARSER.parse(post_date));

                    // 排序
                    expense.setOrderIndex(++order);
                    // 交易时间
                    expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(trans_date));
                    // 币种
                    expense.setCurrencyType("CNY");
                    // 消费金额
                    expense.setAmountMoney(new BigDecimal(amount_money));
                    // 余额
                    expense.setBalance(new BigDecimal(balance));
                    // 交易地点
                    expense.setTransAddr("");
                    // 交易方式
                    expense.setTransMethod("");
                    // 交易通道
                    expense.setTransChannel("");
                    // 描述
                    expense.setDescription(description);
                    // 备注
                    expense.setRemark(remark);
                    // 对方卡号
                    expense.setOppositeCardNo(opposite_card_no);
                    // 对方银行
                    expense.setOppositeBank(opposite_bank);
                    // 对方户名
                    expense.setNameOnOppositeCard(sb.toString());
//				    expense.setNameOnOppositeCard(new String (str.getBytes(),"UTF-8"));
                    billAllData.getShoppingSheets().add(expense);
                }
            }
        }
    } catch (e) {
        logger.error("{},借记卡{}账单抓取异常:{}",context.get(Constants.LUA_TASK_KEY),firstDay,e);
        statCaughtException(context, e);
    }
}

/**
 * 借记卡获取6个月的第一天  格式:2017-01-01
 * @return
 * @throws Exception
 */
function  getMonthFirstDay(){
    var lst = new ArrayList();

    var calendar = new GregorianCalendar();

    for (var i = 0; i < 12; i++) {
        calendar.setTime(new Date());
        calendar.add(Calendar.MONTH, -1 * i);

        var gcLast =  Calendar.getInstance();
        gcLast.setTime(calendar.getTime());
        gcLast.set(Calendar.DAY_OF_MONTH, 1);
        lst.add(depoitSdf.format(gcLast.getTime()));
    }
    return lst;
}

/**
 * 借记卡获取六个月的最后一天,当月就返回到今天
 */
function  getMonthLastDay(){
    var lst = new ArrayList();

    var calendar = new GregorianCalendar();
//		DateFormat dfdate = new SimpleDateFormat("yyyy-MM-dd");
    for (var i = -1; i < 11; i++) {

        calendar.setTime(new Date());
        calendar.add(Calendar.MONTH, -1 * i);

        var gcLast =  Calendar.getInstance();
        gcLast.setTime(calendar.getTime());
        gcLast.set(Calendar.DATE, 1);
        gcLast.add(Calendar.DATE, -1);
        if (gcLast.getTime().after(new Date())) {
            lst.add(depoitSdf.format(new Date()));
        } else {
            lst.add(depoitSdf.format(gcLast.getTime()));
        }
    }
    return lst;
}

/**
 * 借记卡的基本信息
 * @param creditCardAllData
 * @param param
 * @param cardNum
 * @throws Exception
 */
function parseBaseInfo( creditCardAllData,  param, cardNum) {
    logger.info("{},开始抓取借记卡基本信息",context.get(Constants.LUA_TASK_KEY));
    try {
        //卡id
        creditCardAllData.setCardId(UUID.randomUUID().toString());
        //卡类型
        creditCardAllData.setCardType("借记卡");
        //卡名字
        creditCardAllData.setBankName("兴业银行");
        creditCardAllData.setCashBalance(null);
        creditCardAllData.setCashLimit(null);
        creditCardAllData.setCreditLimit(null);
        /**
         * 开户行
         */
        var openBankURL = "https://3g.cib.com.cn/app/20901.html" ;
        param.clear();
        param.put("flowsn", "0");
        param.put("listcardno", "0");
        param.put("listno", "0");
        var openBankHtml =RequestUtil.post(openBankURL,param,getHttpPostTwo());
        storeDataToFile(context,openBankHtml, cardNum + "_openBankXml.html");
        if(openBankHtml.contains("该业务仅支持借记卡办理，请使用借记卡登录后继续办理")){
            throw  new BankException(BALO_99603_15, errorMsgMap.get(BALO_99603_15));
        }
        var openBankDoc = Jsoup.parse(openBankHtml);
        var openBank = openBankDoc.select("body > div.content > div.purchase-info > ul > li.top-inline.clearfix > span").text().trim().replaceAll("\\u00A0", "");
        var fullcardNum = openBankDoc.select("body > div.content > form > div.card-info.card_bg > div.card-account > em:nth-child(2)").text().trim().replaceAll("\\u00A0", "").replaceAll("\\s*","");
        var name = openBankDoc.select("body > div.content > form > div.card-info.card_bg > div:nth-child(2) > span.fl.mat5").text().trim().replaceAll("\\u00A0", "");;
        //完整卡号
        creditCardAllData.setFullCardNum(fullcardNum);
        //卡号后四位
        creditCardAllData.setCardNum(fullcardNum.substring((fullcardNum.length()-4), (fullcardNum.length())));
        //开户行
        creditCardAllData.setOpenBank(openBank);
        //持卡人
        creditCardAllData.setNameOnCard(name);

        var baseURL="https://3g.cib.com.cn/app/80820.html";
        param.put("flowsn", "50");
        param.put("secmenu", "0200000300");
        var baseHtml =RequestUtil.post(baseURL,param,getHttpPostTwo());
        storeDataToFile(context,baseHtml, cardNum + "_card.html");
        var baseDoc = Jsoup.parse(baseHtml);

        //币种
        currency_type = convertCurr(baseDoc.select("body > div.content > form:nth-child(1) > div > div > p").text()
            .replaceAll("活期可用余额", ""));
        var huoTwoUrl = "https://3g.cib.com.cn/app/10020.html";
        param.clear();
        param.put("flowsn", "201");
        param.put("listcardno", "0");
        param.put("listno", "0");
        var huoTwoHtml = RequestUtil.post(huoTwoUrl,param,getHttpPostOne());
        storeDataToFile(context,huoTwoHtml, cardNum + "_card_huotwo.html");

        var huoTwoDoc = Jsoup.parse(huoTwoHtml);
        var tables = huoTwoDoc.select("table");
        var balanceSum = 0.0;
        for (var i = 0; i < tables.size() - 1; i++) {
            var text = huoTwoDoc.select("body > div.content > form > table:nth-child(" + (4 + i)
                + ") > tbody > tr:nth-child(1) > td:nth-child(1)").text().trim();
            if (equals(text,"人民币活期存款")) {
                var 	balance= huoTwoDoc.select("body > div.content > form > table:nth-child(4) > tbody > tr:nth-child(2) > td:nth-child(1)").text().replaceAll("账户余额：", "").replaceAll(",", "");
                balanceSum = balanceSum + Double.parseDouble(balance);
                var huoqiURL = "https://3g.cib.com.cn/app/10020.html";
                param.clear();
                param.put("flowsn", "250");
                param.put("mxlistno", "001");
                param.put("cardindex", "0");
                var huoqiBaseHtml = RequestUtil.post(huoqiURL,param,getHttpPostThree());
                storeDataToFile(context,huoqiBaseHtml, cardNum + "_card_kaihu.html");
                var huoqiBaseDoc = Jsoup.parse(huoqiBaseHtml);
                //开户时间
                open_time = huoqiBaseDoc.select("body > div.content > div.product-introduce > div:nth-child(4) > div:nth-child(1) > span").text().trim().replaceAll("/", "-");
                // 开户时间
                creditCardAllData.setOpenTime(yyyy_MM_dd_PARSER.parse(open_time));
            }else if(text.equals("人民币定期存款")){
                var 	balance= huoTwoDoc.select("body > div.content > form > table:nth-child(5) > tbody > tr:nth-child(1) > td:nth-child(2)").text().trim().replaceAll(",", "");
                balanceSum = balanceSum + Double.parseDouble(balance);
            }
        }
        creditCardAllData.setBalance(new BigDecimal(String.valueOf(balanceSum)));
    } catch (e) {
        logger.error("{},借记卡基本信息抓取异常:{}",context.get(Constants.LUA_TASK_KEY),e);
        statCaughtException(context, e);
    }
}

/** 信用卡开始抓取
 * @param creditCardAllData
 * @param param
 * @throws IOException
 * @throws ClientProtocolException
 * @throws Exception
 */
function  creditCrawl( creditCardAllData, param) {
    logger.info("{},信用卡抓取开始",context.get(Constants.LUA_TASK_KEY));
    var bills = new ArrayList();
    var creditCardTimeDeposits = new ArrayList();
    creditCardAllData.setDeposits(creditCardTimeDeposits);
    creditCardAllData.setBills(bills);
    date = getDateFun(param);//账单日
    date = equals(date,"") ? "1" : date;
    logger.info("{},帐单日:{}",context.get(Constants.LUA_TASK_KEY),date);
    getBasicNeedInfo(creditCardAllData, param, cardNum);
    creditBill(creditCardAllData , param , bills);
    var billAllData = new BillAllData();
    // 未出账单
    parseBillInfoDetailUNDONE(param, creditCardAllData, cardNum, date, billAllData);
    bills.add(billAllData);
}

/**
 * 已出账单开始查询
 * @param creditCardAllData
 * @param param
 * @param bills
 * @throws Exception
 */
function    creditBill( creditCardAllData , param , bills) {

    // 查询6个月的
    var dates = getRecentMonth();
    Collections.reverse(dates);
    for (var i = 0; i < dates.size(); i++) {
        //System.out.println(options.get(i).text().replaceAll("/", ""));
        var billDate = dates.get(i);
        var billAllData = new BillAllData();
        billAllData.setBillId(UUID.randomUUID().toString());
        billAllData.setBillType("DONE");
        billAllData.setBankName("兴业银行");// yyyyMM
        billAllData.setBillMonth(billDate);
        if(date.equals("")){
            billAllData.setBillDate(yyyy_MM_dd_PARSER.parse(billDate + "-01" ));
        }else {
            billAllData.setBillDate(yyyy_MM_dd_PARSER.parse(billDate + "-" + date));
        }

        billAllData.setUsdNewBalance(null);
        billAllData.setUsdMinPayment(null);
        billAllData.setUsdLastBalance(null);
        billAllData.setUsdLastPayment(null);
        billAllData.setUsdNewCharges(null);
        billAllData.setInterest(null);
        billAllData.setUsdInterest(null);
        billAllData.setUsdCreditLimit(null);
        billAllData.setUsdCashLimit(null);

        // 信用额度相关
        billAllData.setCreditLimit(creditCardAllData.getCreditLimit());
        billAllData.setCashLimit(creditCardAllData.getCashLimit());
        var billdata = billDate.substring(5, 7);
//			String billTemp = billdata;
        var calendar = Calendar.getInstance();
        var year = calendar.get(Calendar.YEAR);
        year = Integer.parseInt(year);
        var mon = Integer.parseInt(billdata) + 1;
        mon = Integer.parseInt(mon);
//			int currentMon = Integer.parseInt(billdata);
        if (mon < 10) {
            billdata = "0" + mon;
        }else if(mon > 12){
            billdata = "0" + (mon - 12);
        } else {
            billdata = "" + mon;
            /*if(Integer.parseInt(billTemp) == 12){
             year = year + 1;
             billdata = String.valueOf(mon - Integer.parseInt(billTemp));
             }*/
        }
        billAllData.setPaymentDueDate(yyyy_MM_dd_PARSER.parse(year + "-" + billdata + "-" + "08"));
        billDate = billDate.replaceAll("-", "");
        // 抓取已出账单
        parseBillInfoDetailNew(param, creditCardAllData, billDate, cardNum, mon, billAllData);

        var lastPayment = context.get("pay");
        if (lastPayment !==  null) {
            last_payment = new BigDecimal("-" + String.format("%.2f", lastPayment));
        } else {
            last_payment = new BigDecimal(0.0);
        }
        billAllData.setLastPayment(last_payment);
        if(i == 0){
            billAllData.setLastBalance(null);
        }else {
            billAllData.setLastBalance(last_balance);
        }

        last_balance = billAllData.getNewBalance();
        bills.add(billAllData);
    }
}

/**
 * 账单日查询
 *
 * @throws IOException
 * @throws ClientProtocolException
 */
function  getDateFun(map)  {
    var dataURL = "https://3g.cib.com.cn/app/10000.html";
    map.clear();
    map.put("flowsn", "50");
    map.put("secmenu", "0300001054");

    var hear = new HashMap();
    hear.put("Referer", "https://3g.cib.com.cn/app/10000.html");
    hear.put("Origin", "https://3g.cib.com.cn");
    hear.put("Host", "3g.cib.com.cn");
    hear.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");

    var dateHtml = RequestUtil.post(dataURL,map,hear);
    storeDataToFile(context,dateHtml, "billdata.html");
    var dateDoc = Jsoup.parse(dateHtml);
    var table = dateDoc.select("table.MBcontent1:nth-child(1)").first();
//		Element table = dateDoc.select("body > div:nth-child(2) > form > table").get(0);
    var dataText = "";
    if(table !== null){
        var trs = table.select("tr");

        if (trs.size() == 6) {// li
            dataText = dateDoc
                .select("body > div:nth-child(3) > form > table > tbody > tr:nth-child(4) > td:nth-child(3)").text()
                .trim();
//            body > div:nth-child(3) > form > table > tbody > tr:nth-child(4) > td:nth-child(3)
        } else if (trs.size() == 7) {// han

            dataText = dateDoc
                .select("table.MBcontent1:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(3)").text()
                .trim();
        }
    }

    return RegexUtils.GetText(dataText, "[0-9]{2}");
}

/**
 * 未出账单查询
 * @param param
 * @param creditCardAllData
 * @param cardNum
 * @param date
 * @param billAllData
 * @throws ClientProtocolException
 * @throws IOException
 */
function parseBillInfoDetailUNDONE( param, creditCardAllData,  cardNum,  date,  billAllData){
    logger.info("{},开始抓取未出账单",context.get(Constants.LUA_TASK_KEY));
    try {
        billAllData.setBillId(UUID.randomUUID().toString());
        billAllData.setBillType("UNDONE");
        billAllData.setBankName("兴业银行");
        billAllData.setUsdNewBalance(null);
        billAllData.setUsdMinPayment(null);
        billAllData.setUsdLastBalance(null);
        billAllData.setUsdLastPayment(null);
        billAllData.setUsdNewCharges(null);
        billAllData.setInterest(null);
        billAllData.setUsdInterest(null);
        billAllData.setUsdCreditLimit(null);
        billAllData.setUsdCashLimit(null);
        billAllData.setLastPayment(null);
        billAllData.setMinPayment(null);
        billAllData.setCashLimit(creditCardAllData.getCashLimit());
        billAllData.setCreditLimit(creditCardAllData.getCreditLimit());
        logger.info("{},上期账单金额:{}",context.get(Constants.LUA_TASK_KEY),context.get("sumBalance"));
        billAllData.setLastBalance(null !== context.get("sumBalance") ? new BigDecimal(context.get("sumBalance")):null);

        var calendar = Calendar.getInstance();
        var day = calendar.get(Calendar.DAY_OF_MONTH);
        day =  Integer.parseInt(day);
        if( date !== ""){
            if (day > Integer.parseInt(date)) {
                calendar.add(Calendar.MONTH, 1);
            }
        }
        var billdate = creditSdf.format(calendar.getTime());

        billAllData.setBillMonth(billdate);
        billAllData.setBillDate(yyyy_MM_dd_PARSER.parse(billdate + "-" + date));
        billAllData.setPaymentDueDate(null);

        var bills = creditCardAllData.getBills();
        if (bills == null) {
            bills = new ArrayList();
        }

        var shopping_sheets = new ArrayList();
        var installments = new ArrayList();
        billAllData.setInstallments(installments);

        param.clear();
        param.put("flowsn", "50");
        param.put("secmenu", "0300001052");
        var fiveUrl = "https://3g.cib.com.cn/app/10000.html";
        var zdHtml = RequestUtil.post(fiveUrl,param,getHttpPostCreditOne());
        storeDataToFile(context,zdHtml, cardNum + "_bill_out_1Page.html");
        var docs = Jsoup.parse(zdHtml);
        //获取当前页和总页数 ===[1/2]
        var totalPageForm = docs.select("form:nth-child(2)").text().replaceAll("下一页", "").trim();

        var tablem = docs.select("table");
        if (tablem.size() == 2){
            return;
        }

        var tables = docs.select("table");
        var index = 1;
        var lastPayment = 0.0 ;
        var newCharges = 0.0;
        var newBalance = 0.0;
        if (tables.size() > 1) {
            var table2 = tables.get(2);
            var mxtrs = table2.select("tr");


            for (var i = 3; i < mxtrs.size() - 2; i++) {
                var tds = mxtrs.get(i).children();
                var expense = new Expense();
                var jyr = tds.get(1).text().trim();
                var je = tds.get(2).text().trim().replaceAll("\\s*", "");
                var zy = tds.get(3).text().trim();
                newBalance = Double.parseDouble(je) + newBalance;
                if(zy.contains("转入") || zy.contains("还款")){
                    lastPayment = Double.parseDouble(je) + lastPayment ;
                }

                if (!je.contains("-")) {
                    newCharges = Double.parseDouble(je) + newCharges ;
                }
                expense.setId(UUID.randomUUID().toString());
                expense.setCardNum(creditCardAllData.getCardNum());// 卡号后四位
                expense.setCurrencyType("CNY");// 交易币种
                expense.setAmountMoney(new BigDecimal(je));// 交易金额
                expense.setOrderIndex(index ++);// 索引
                // 交易时间
                expense.setTransDate(
                    yyyy_MM_dd_HH_mm_ss_PARSER.parse(processDate(jyr).replaceAll("(?<=^\\d{4})", "-").replaceAll("(?<=^\\d{4}\\-\\d{2})", "-")
                    + " 00:00:00"));
                // 以下没数据
                expense.setPostDate(
                    yyyy_MM_dd_PARSER.parse(processDate(jyr).replaceAll("(?<=^\\d{4})", "-").replaceAll("(?<=^\\d{4}\\-\\d{2})", "-")));
                expense.setCategory(getCreditCategory("CIB",zy, je));
                expense.setBalance(null);
                expense.setTransAddr("");
                expense.setTransMethod("");
                expense.setTransChannel("");
                expense.setRemark("");
                expense.setDescription(zy);
                expense.setOppositeBank("");
                expense.setNameOnOppositeCard("");
                expense.setOppositeCardNo("");
                shopping_sheets.add(expense);
            }
        }

        // 判断是否还有下一页
        if(totalPageForm !== ""){
            for (var currentPage = 2; currentPage <= getFen(totalPageForm).size(); currentPage ++) {
                // 进行请求
                param.clear();
                var pageUrl = "https://3g.cib.com.cn/app/50020.html";
                param.put("beginNo", "11");
                param.put("flowsn", "70");
                var pageHtml = RequestUtil.post(pageUrl,param,getHttpPostCreditThree());
                storeDataToFile(context,pageHtml, cardNum + "_bill_out_"+ currentPage +"Page.html");
                var pageHtmlDc = Jsoup.parse(pageHtml);

                var tablesPage = pageHtmlDc.select("table");
                if (tablesPage.size() > 1) {
                    var table2 = tablesPage.get(2);
                    var mxtrs = table2.select("tr");
                    for (var i = 3; i < mxtrs.size() - 2; i++) {
                        var tds = mxtrs.get(i).children();
                        var expense = new Expense();
                        var jyr = tds.get(1).text().trim();
                        var je = tds.get(2).text().trim().replaceAll("\\s*", "");
                        var zy = tds.get(3).text().trim();
                        newBalance = Double.parseDouble(je) + newBalance;
                        if(zy.contains("转入") || zy.contains("还款")){
                            lastPayment = lastPayment + Double.parseDouble(je);
                        }

                        if (!je.contains("-")) {
                            newCharges = Double.parseDouble(je) + newCharges ;
                        }
                        expense.setAmountMoney(new BigDecimal(je));// 交易金额
                        expense.setId(UUID.randomUUID().toString());
                        expense.setCardNum(creditCardAllData.getCardNum());// 卡号后四位
                        expense.setCurrencyType("CNY");// 交易币种
                        expense.setOrderIndex(++index);// 索引
                        // 交易时间
                        expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(processDate(jyr).replaceAll("(?<=^\\d{4})", "-")
                                .replaceAll("(?<=^\\d{4}\\-\\d{2})", "-") + " 00:00:00"));
                        // 以下没数据
                        expense.setPostDate(yyyy_MM_dd_PARSER.parse(processDate(jyr).replaceAll("(?<=^\\d{4})", "-")
                            .replaceAll("(?<=^\\d{4}\\-\\d{2})", "-")));

                        expense.setCategory(getCreditCategory("CIB",zy, je));
                        expense.setBalance(null);
                        expense.setTransAddr("");
                        expense.setTransMethod("");
                        expense.setTransChannel("");
                        expense.setRemark("");
                        expense.setDescription(zy);
                        expense.setOppositeBank("");
                        expense.setNameOnOppositeCard("");
                        expense.setOppositeCardNo("");
                        shopping_sheets.add(expense);
                    }
                }
            }
        }
        var sumBalance =  context.get("sumBalance");
        logger.info("{},上期-----:{}",context.get(Constants.LUA_TASK_KEY),sumBalance);
        if(sumBalance !== null){
            newBalance = newBalance +  Double.parseDouble(sumBalance);
        }
        billAllData.setLastPayment(new BigDecimal(String.format("%.2f", lastPayment)));
        billAllData.setNewBalance(new BigDecimal(String.format("%.2f", newBalance)));
        billAllData.setNewCharges(new  BigDecimal(String.format("%.2f", newCharges)));
        billAllData.setShoppingSheets(shopping_sheets);
    } catch (e) {
        logger.error("{},未出账单抓取异常:{}",context.get(Constants.LUA_TASK_KEY),e);
        statCaughtException(context, e);
    }
}

/**
 * 信用卡的六个月
 * @return
 */
function getRecentMonth() {
    var dates = new ArrayList();
    var calendar = Calendar.getInstance();
    for (var i = 0; i > -6; i--) {
        var day = calendar.get(Calendar.DAY_OF_MONTH);
        day = Integer.parseInt(day);
        if (day <= Integer.parseInt(date)) {
            calendar.add(Calendar.MONTH, -1);
            dates.add(creditSdf.format(calendar.getTime()));
        } else {
            dates.add(creditSdf.format(calendar.getTime()));
            calendar.add(Calendar.MONTH, -1);
        }
    }
    return dates;
}

/**
 * 已出账单
 *
 * @param param
 * @param creditCardAllData
 * @param billDate
 * @throws Exception
 */
function parseBillInfoDetailNew(  param, creditCardAllData,  billDate,  cardNum,  mon,  billAllData) {
    logger.info("{},抓取{}已出账单",context.get(Constants.LUA_TASK_KEY), billDate);
    try {
        var bills = creditCardAllData.getBills();
        if (bills == null) {
            bills = new ArrayList();
        }

        var shopping_sheets = new ArrayList();
        var installments = new ArrayList();
        // 分期
        billAllData.setInstallments(installments);

        param.clear();
        param.put("bbxx", "01");
        param.put("h2", "submiturl=50002_1|flowsn=-100");
        param.put("h3", "submiturl=50003_1|flowsn=-100");
        param.put("querydate", billDate);
        param.put("mainflag", "1");
        var fiveUrl = "https://3g.cib.com.cn/app/50002.html";
        var zdHtml =RequestUtil.post(fiveUrl,param,getHttpPostCreditTwo());
        storeDataToFile(context,zdHtml, cardNum + "_bill_" + billDate + "Mon.html");

        if (zdHtml.contains("错误提示页面")) {
            return;
        }

        var doc = Jsoup.parse(zdHtml);
        var tablem = doc.select("table");
        if (tablem.size() == 2){
            return;
        }

        var table = doc.select("table.MBcontent1:nth-child(3)");
        var trs = null ;
        if(table !==  null){
            trs = table.select("tr");
        }
        // 账单日期
//		String billDates = "";
        // 最低还款
        var minRepayment = "";
        // 还款日
        var repaymentDate = "";
        // 本期应还总额
        var sumBalance = "";
        var moneySum = 0;
        var pay = 0;

        if (trs.size() == 13) {// han
            // 账单日期 body > div:nth-child(2) > table:nth-child(3) > tbody >
            // tr:nth-child(3) > td:nth-child(3)
            /*billDates = doc
             .select("table.MBcontent1:nth-child(3) > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(3)")
             .text().trim();*/
            // 最低还款
            minRepayment = doc
                .select("table.MBcontent1:nth-child(3) > tbody:nth-child(1) > tr:nth-child(8) > td:nth-child(2)")
                .text().trim();
            // 还款日
            repaymentDate = doc
                .select("table.MBcontent1:nth-child(3) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(2)")
                .text().trim();
            // 本期应还总额
            sumBalance = doc
                .select("table.MBcontent1:nth-child(3) > tbody:nth-child(1) > tr:nth-child(7) > td:nth-child(2)")
                .text().trim();
            // 币种------------账单详情页面需要
            currecy = doc
                .select("table.MBcontent1:nth-child(3) > tbody:nth-child(1) > tr:nth-child(6) > td:nth-child(2)")
                .text().trim();
        } else if (trs.size() == 12) {// li
            // 账单日期 body > div:nth-child(2) > table:nth-child(3) > tbody >
            // tr:nth-child(3) > td:nth-child(3)
            /*	billDates = doc
             .select("body > div:nth-child(2) > table:nth-child(3) > tbody > tr:nth-child(3) > td:nth-child(3)")
             .text().trim();*/
            // 最低还款
            minRepayment = doc
                .select("body > div:nth-child(3) > table:nth-child(3) > tbody > tr:nth-child(7) > td:nth-child(2)")
                .text().trim();
            // 还款日
            repaymentDate = doc
                .select("body > div:nth-child(3) > table:nth-child(3) > tbody > tr:nth-child(4) > td:nth-child(2)")
                .text().trim();
            // 本期应还总额
            sumBalance = doc
                .select("body > div:nth-child(3) > table:nth-child(3) > tbody > tr:nth-child(6) > td:nth-child(2)")
                .text().trim();
            // 币种------------账单详情页面需要
            currecy = doc
                .select("body > div:nth-child(3) > table:nth-child(3) > tbody > tr:nth-child(5) > td:nth-child(2)")
                .text().trim();
        }

        // billAllData.setBillDate(processDate(billDates).replaceAll("(?<=^\\d{4})",
        // "-").replaceAll("(?<=^\\d{4}\\-\\d{2})", "-"));
        billAllData.setPaymentDueDate(
            yyyy_MM_dd_PARSER.parse(processDate(repaymentDate).replaceAll("(?<=^\\d{4})", "-").replaceAll("(?<=^\\d{4}\\-\\d{2})", "-")));
        billAllData.setMinPayment(new BigDecimal(minRepayment));
        context.put("sumBalance", sumBalance);
        billAllData.setNewBalance(new BigDecimal(String.format("%.2f", Double.parseDouble(sumBalance))));

        var sixUrl = "https://3g.cib.com.cn/app/50003.html";
        var zdmxHtml = RequestUtil.post(sixUrl,param,getHttpPostCreditTwo());
        storeDataToFile(context,zdmxHtml, cardNum + "_bill_shopping_sheets_" + billDate + "Mon_1Page" + ".html");
        if (zdmxHtml.contains("错误提示页面")) {
            return;
        }
        var docs = Jsoup.parse(zdmxHtml);
        // 总页数
        var sumPages = docs
            .select("body > div:nth-child(3) > table:nth-child(5) > tbody > tr:nth-child(14) > td:nth-child(2) > form")
            .text().replaceAll("下一页", "").replaceAll("\\[", "").replaceAll("\\]", "");
        var sumPage = null;
        if (sumPages !== "") {
            sumPage = sumPages.split("/");
        }

        var tables = docs.select("table");
        var je = "";

        var index = 0;
        var ins;
        if (tables.size() > 2) {
            var table2 = tables.get(3);
            var mxtrs = table2.select("tr");

            for (var i = 3; i < mxtrs.size() - 6; i++) {
//				item = item ++;
                var expense = new Expense();
                var tds = mxtrs.get(i).children();
                var jyr = tds.get(1).text().trim();
                je = tds.get(2).text().trim();
                var zy = tds.get(3).text().trim().replaceAll("\\u00A0", "");

                if (!je.contains("-")) {
                    var je1 = Double.parseDouble(je);
                    moneySum = moneySum + je1;
                    billAllData.setNewCharges(new BigDecimal(String.format("%.2f", moneySum)));
                }else if(je.contains("-")){
                    //本期已还款金额===对应的上期已还款金额(last_payment)
                    pay = pay + Double.parseDouble(je.replaceAll("-", ""));
                    context.put("pay", pay);
                }
                expense.setId(UUID.randomUUID().toString());
                expense.setCardNum(creditCardAllData.getCardNum());// 卡号后四位
                expense.setDescription(zy);
                // 交易时间
                expense.setTransDate(
                    yyyy_MM_dd_HH_mm_ss_PARSER.parse(processDate(jyr).replaceAll("(?<=^\\d{4})", "-").replaceAll("(?<=^\\d{4}\\-\\d{2})", "-")
                    + " 00:00:00"));
                // 以下没数据
                expense.setPostDate(
                    yyyy_MM_dd_PARSER.parse(processDate(jyr).replaceAll("(?<=^\\d{4})", "-").replaceAll("(?<=^\\d{4}\\-\\d{2})", "-")));

                expense.setAmountMoney(new BigDecimal(je));// 交易金额
                expense.setOrderIndex(++index);// 索引
                expense.setBalance(null);
                expense.setTransAddr("");
                expense.setTransMethod("");
                expense.setTransChannel("");
                expense.setCategory(getCreditCategory("CIB",zy, je));
                expense.setRemark("");
                expense.setOppositeBank("");
                expense.setNameOnOppositeCard("");
                expense.setOppositeCardNo("");
                expense.setOppositeBank("");
                expense.setCurrencyType("CNY");// 交易币种
                shopping_sheets.add(expense);

                if (isNumExists(zy) && (zy.contains("账单分期") || (!zy.contains(":") && zy.contains("客服") && !zy.contains("：")  && !zy.contains("转分期")) || zy.contains("现分") || (zy.contains("电销") && !zy.contains("转分期")) || zy.contains("短信消")
                        || zy.contains("中国铁路") || zy.contains("新兴业") || zy.contains("智付电子") || zy.contains("手机") || zy.contains("巴龙庄园") || zy.contains("波尔多") || zy.contains("网易宝") || zy.contains("波拿大帝")  || zy.contains("微信")
                    )) {//分期
                    if(getFen(zy).size() > 1){
                        ins = new Installment();
                        billAllData.getInstallments().add(ins);
                        ins.setShoppingsheetId(UUID.randomUUID().toString());
                        // 本期金额
                        ins.setAmountMoney(new BigDecimal(je));
                        // 记账日期
                        ins.setPostDate(yyyy_MM_dd_PARSER.parse(jyr.replaceAll("/", "-")));
                        // 交易日期
                        ins.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(jyr.replaceAll("/", "-") + " 00:00:00"));
                        // 分期描述
                        ins.setInstallmentDesc(zy);
                        // 分期转账手续费描述
                        ins.setTransferfeeDesc("");
                        // 分期类型
                        ins.setInstallmentType("BILL");
                        // 币种
                        ins.setCurrencyType("CNY");
                        // 转账手续费
                        ins.setTransferFee(null);
                        if((i + 1) <= mxtrs.size() - 6){
                            var element = mxtrs.get(i+1).children();
                            if(element.size() == 5 ){

                                var handFeeDes = element.get(3).text().trim().replaceAll("\\u00A0", "");
                                logger.info("{},这是下一条,手续费描述:{}",context.get(Constants.LUA_TASK_KEY),handFeeDes);
                                var handFee = element.get(2).text().trim();//下一条的手续费
                                if (!handFeeDes.matches(".*第\\d*期共\\d*期") &&  !handFeeDes.contains("分期付款费用") ){
　　　　　　　　　　　　　　　　　      continue;
                                    }
                                if(getFen(handFeeDes).size() > 1 && getFen(handFeeDes).get(0) == getFen(zy).get(1)){

                                    if(handFeeDes.startsWith("分期付款费用")){
                                        ins.setHandingFee(new BigDecimal(handFee));// 手续费
                                        ins.setHandingfeeDesc(handFeeDes);// 分期手续费描述
                                    }
                                }
                                if((i - 1) <= mxtrs.size() - 6){
                                    var element1 = mxtrs.get(i-1).children();
                                    var handFeeDesUp = element1.get(3).text().trim().replaceAll("\\u00A0", "");
                                    logger.info("{},这是上一条,手续费描述:{}",context.get(Constants.LUA_TASK_KEY),handFeeDesUp);
                                    var handFeeUp = element1.get(2).text().trim();
                                    if (!handFeeDesUp.matches(".*第\\d*期共\\d*期") &&  !handFeeDesUp.contains("分期付款费用")){
                                        continue;
                                    }
                                    //TO:防止上一条的分期付款费用不是本期账单的手续费
                                    if(getFen(handFeeDesUp).size() > 1 && getFen(handFeeDesUp).get(0) == getFen(zy).get(1)){

                                        if(handFeeDesUp.startsWith("分期付款费用")){
                                            ins.setHandingFee(new BigDecimal(handFeeUp));// 手续费
                                            ins.setHandingfeeDesc(handFeeDesUp);// 分期手续费描述
                                        }
                                    }
                                }
                            }
                            if((i - 1) <= mxtrs.size() - 6){
                                var element1 = mxtrs.get(i-1).children();
                                var handFeeDes = element1.get(3).text().trim().replaceAll("\\u00A0", "");
                                logger.info("{},这是上一条,手续费描述:{}",context.get(Constants.LUA_TASK_KEY),handFeeDes);
                                var handFee = element1.get(2).text().trim();
                                if(handFeeDes.startsWith("分期付款费用")){
                                    ins.setHandingFee(new BigDecimal(handFee));// 手续费
                                    ins.setHandingfeeDesc(handFeeDes);// 分期手续费描述
                                }
                            }
                        }


                        // if(isNumExists(zy)){
                        if (getFen(zy).size() == 3) {
                            //当前分期数
                            ins.setCurrentMonth(getFen(zy).get(1));
                            // 总分期数
                            ins.setTotalMonth(getFen(zy).get(2));
                        } else if (getFen(zy).size() == 2){
                            ins.setCurrentMonth(getFen(zy).get(0));
                            // 总分期数
                            ins.setTotalMonth(getFen(zy).get(1));
                        }

                    }
                }else if (zy.contains("分期付款费用")) {// 就是分期手续费
                    if(i == 12){
                        context.put("handfee", je);
                        context.put("handfeedes", zy);
                    }else {
                        continue;
                    }

                }
            }
        }

        if (sumPages !== "") {
            var ins1= null ;
            // 分页
            for (var j = 2; j <= Integer.parseInt(sumPage[1].replaceAll(" ", "")); j++) {
                var pageURL = "https://3g.cib.com.cn/app/50003.html";
                param.clear();
                param.put("beginNo", (j - 1) + "1");
                param.put("flowsn", "70");
                var pageHtml =RequestUtil.post(pageURL,param,getHttpPostCreditTwo());
                storeDataToFile(context,pageHtml, cardNum + "_bill_shopping_sheets_" + billDate+ "-"+j+"Page.html");
                var pageDoc = Jsoup.parse(pageHtml);
                var tablesPage = pageDoc.select("table");
//				int item = 1;
                if (tables.size() > 2) {
                    var table2 = tablesPage.get(3);
                    var mxtrs = table2.select("tr");
                    for (var i = 3; i < mxtrs.size() - 6; i++) {
                        var expense = new Expense();
//						item = item ++;
                        var tds = mxtrs.get(i).children();
                        var jyr = tds.get(1).text().trim();
                        je = tds.get(2).text().trim();
                        var zy = tds.get(3).text().trim().replaceAll("\\u00A0", "");
//						logger.info("{}月，金额{}",billDate , je);
                        if (!je.contains("-")) {
                            var je1 = Double.parseDouble(je);
                            moneySum = moneySum + je1;
                            billAllData.setNewCharges(new BigDecimal(String.format("%.2f", moneySum)));
                        }else if(je.contains("-")){
                            ////本期已还款金额===对应的上期已还款金额(last_payment)
                            pay = pay + Double.parseDouble(je.replaceAll("-", ""));
                            context.put("pay", pay);
                        }
                        expense.setCategory(getCreditCategory("CIB",zy, je));
                        expense.setId(UUID.randomUUID().toString());
                        expense.setCardNum(creditCardAllData.getCardNum());// 卡号后四位
                        expense.setDescription(zy);
                        // 交易时间
                        expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(processDate(jyr).replaceAll("(?<=^\\d{4})", "-")
                                .replaceAll("(?<=^\\d{4}\\-\\d{2})", "-") + " 00:00:00"));
                        // 以下没数据
                        expense.setPostDate(yyyy_MM_dd_PARSER.parse(processDate(jyr).replaceAll("(?<=^\\d{4})", "-")
                            .replaceAll("(?<=^\\d{4}\\-\\d{2})", "-")));
                        expense.setAmountMoney(new BigDecimal(je));// 交易金额
                        expense.setOrderIndex(++index);// 索引
                        expense.setBalance(null);
                        expense.setTransAddr("");
                        expense.setTransMethod("");
                        expense.setTransChannel("");
                        expense.setRemark("");
                        expense.setOppositeBank("");
                        expense.setNameOnOppositeCard("");
                        expense.setOppositeCardNo("");
                        expense.setOppositeBank("");
                        expense.setCurrencyType("CNY");// 交易币种
                        shopping_sheets.add(expense);

                        if (isNumExists(zy) && (zy.contains("账单分期") || ( !zy.contains(":") && zy.contains("客服") && !zy.contains("：")  && !zy.contains("转分期")) || zy.contains("现分") || (zy.contains("电销") && !zy.contains("转分期") ) || zy.contains("短信消")
                                || zy.contains("中国铁路") || zy.contains("新兴业") || zy.contains("智付电子") || zy.contains("手机") || zy.contains("巴龙庄园") || zy.contains("波尔多") || zy.contains("网易宝") || zy.contains("波拿大帝")  || zy.contains("微信")
                            )) {// 分期
                            if(getFen(zy).size() > 1){
                                ins1 = new Installment();
                                billAllData.getInstallments().add(ins1);
                                ins1.setShoppingsheetId(UUID.randomUUID().toString());
                                // if (zy.startsWith("分期付款费用")) {

                                // }else {
                                // 记账日期
                                ins1.setPostDate(yyyy_MM_dd_PARSER.parse(jyr.replaceAll("/", "-")));
                                // 交易日期
                                ins1.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(jyr.replaceAll("/", "-") + " 00:00:00"));
                                // 本期金额
                                ins1.setAmountMoney(new BigDecimal(je));
                                // 分期描述
                                ins1.setInstallmentDesc(zy);                        //分期付款费用 8 12
                                // 分期转账手续费描述
                                ins1.setTransferfeeDesc("");
                                // 分期类型
                                ins1.setInstallmentType("BILL");
                                // 币种
                                ins1.setCurrencyType("CNY");
                                // 转账手续费
                                ins1.setTransferFee(null);
                                //客服消费 8 12
                                if((i + 1) <= mxtrs.size() - 6){                     //分期付款费用  9 12
                                    var element = mxtrs.get(i+1).children();
                                    //长度等于5 是为了防止有上一页这几个字
                                    if(element.size() == 5){
                                        var handFeeDes = element.get(3).text().trim().replaceAll("\\u00A0", "");
                                        logger.info("{},这是下一条,手续费描述:{}",context.get(Constants.LUA_TASK_KEY),handFeeDes);
                                        var handFee = element.get(2).text().trim();//分期手续费

                                        if (!handFeeDes.matches(".*第\\d*期共\\d*期") &&  !handFeeDes.contains("分期付款费用")){
                                            continue;
                                           }
                                        //取手续费里面的数字放到集合的长度大于1（防止光有分期付款费用 没有数字）并且分期副快费用中的当前分期等于描述中的当前分期
                                        if(getFen(handFeeDes).size() > 1 && getFen(handFeeDes).get(0) == getFen(zy).get(1) ){

                                            if(handFeeDes.startsWith("分期付款费用")){
                                                ins1.setHandingFee(new BigDecimal(handFee));// 手续费
                                                ins1.setHandingfeeDesc(handFeeDes);// 分期手续费描述
                                            }/*else if(item == 1){
                                             if(!"".equals(hand.get("handfee")) && null != hand.get("handfee")){

                                             ins1.setHandingFee(new BigDecimal(hand.get("handfee")));// 手续费
                                             }
                                             ins1.setHandingfeeDesc(hand.get("handfeedes"));// 分期手续费描述
                                             }*/
                                        }
                                        if ((i - 1) <= mxtrs.size() - 6) {
                                            var element1 = mxtrs.get(i-1).children();
                                            var handFeeDesUp = element1.get(3).text().trim().replaceAll("\\u00A0", "");
                                            logger.info("{},这是上一条,手续费描述:{}",context.get(Constants.LUA_TASK_KEY),handFeeDesUp);
                                            var handFeeUp = element1.get(2).text().trim();
                                            if (!handFeeDesUp.matches(".*第\\d*期共\\d*期") &&  !handFeeDesUp.contains("分期付款费用")){
                                                continue;
                                            }
                                            //TO:防止上一条的分期付款费用不是本期账单的手续费
                                            if(getFen(handFeeDesUp).size() > 1 && getFen(handFeeDesUp).get(0) == getFen(zy).get(1)){

                                                if(handFeeDesUp.startsWith("分期付款费用")){
                                                    ins1.setHandingFee(new BigDecimal(handFeeUp));// 手续费
                                                    ins1.setHandingfeeDesc(handFeeDesUp);// 分期手续费描述
                                                }
                                            }
                                        }
                                    }
                                    if((i - 1) <= mxtrs.size() - 6){
                                        var element1 = mxtrs.get(i-1).children();
                                        var handFeeDes = element1.get(3).text().trim().replaceAll("\\u00A0", "");
                                        logger.info("{},这是上一条,手续费描述:{}",context.get(Constants.LUA_TASK_KEY),handFeeDes);
                                        var handFee = element1.get(2).text().trim();
                                        if(handFeeDes.startsWith("分期付款费用")){
                                            ins1.setHandingFee(new BigDecimal(handFee));// 手续费
                                            ins1.setHandingfeeDesc(handFeeDes);// 分期手续费描述
                                        }
                                    }
                                }


                                if(i == 3){
                                    var je =  context.get("handfee");
                                    var des =   context.get("handfeedes");
                                    if(getFen(des).size() > 1 && getFen(des).get(0) == getFen(zy).get(1)){
                                        ins1.setHandingFee(new BigDecimal(je));// 手续费
                                        ins1.setHandingfeeDesc(des);// 分期手续费描述
                                    }
                                }

                                // if(isNumExists(zy)){
                                if (getFen(zy).size() == 3) {
                                    // 总分期数
                                    ins1.setTotalMonth(getFen(zy).get(2));
                                    ins1.setCurrentMonth(getFen(zy).get(1));
                                } else if (getFen(zy).size() == 2){
                                    ins1.setCurrentMonth(getFen(zy).get(0));
                                    // 总分期数
                                    ins1.setTotalMonth(getFen(zy).get(1));
                                }


                                // }
                            }
                        } else if (zy.contains("分期付款费用")) {
                            continue;
                        }
                    }
                }
            }
        }
        billAllData.setShoppingSheets(shopping_sheets);
    } catch (e) {
        logger.error("{},{}已出账单抓取异常{}",context.get(Constants.LUA_TASK_KEY),billDate,e);
        statCaughtException(context, e);
    }
}

/**
 * 返回Referer值带有80820的httpost
 * @param
 * @return
 */
function getHttpPostOne(){
    var header = new HashMap();
    header.put("User-Agent",urls.USER_AGENT);
    header.put("Accept",urls.ACCEPT);
    header.put("Host","3g.cib.com.cn");
    header.put("Origin", "https://3g.cib.com.cn");
    header.put("Referer", "https://3g.cib.com.cn/app/80820.html");

    return header;
}

/**
 * 返回referer带有00002的httppost
 * @param
 * @return
 */
function getHttpPostTwo(){

    var header = new HashMap();
    header.put("Referer","https://3g.cib.com.cn/app/00002.html");
    header.put("User-Agent",urls.USER_AGENT);
    header.put("Origin","https://3g.cib.com.cn");
    header.put("Host", "3g.cib.com.cn");
    header.put("Accept", urls.ACCEPT);
    return header;
}

/**
 * 返回referer带有10020的httppost
 * @param
 * @return
 */
function getHttpPostThree(){
    var header = new HashMap();
    header.put("Referer", "https://3g.cib.com.cn/app/10020.html");
    header.put("User-Agent", urls.USER_AGENT);
    header.put("Origin", "https://3g.cib.com.cn");
    header.put("Host", "3g.cib.com.cn");
    header.put("Accept", urls.ACCEPT);
    return header;
}

/**
 * 返回referer带有10040的httppost
 * @param
 * @return
 */
function getHttpPostFour(){

    var header = new HashMap();
    header.put("User-Agent", urls.USER_AGENT);
    header.put("Accept", urls.ACCEPT);
    header.put("Host", "3g.cib.com.cn");
    header.put("Origin", "https://3g.cib.com.cn");
    header.put("Referer", "https://3g.cib.com.cn/app/10040.html");
    return header;
}


/**
 * 判断字符串里面是否包含数字
 * @param description
 * @return
 */
function isNumExists(description) {
    return description.matches(".*\\d+.*");
}

/**
 * 返回Referer值带有80820的httpost
 * @param
 * @return
 */
function  getHttpPostCreditOne(){
    var header = new HashMap();
    header.put("User-Agent", urls.USER_AGENT);
    header.put("Accept", urls.ACCEPT);
    header.put("Host", "3g.cib.com.cn");
    header.put("Origin", "https://3g.cib.com.cn");
    header.put("Referer", "https://3g.cib.com.cn/app/80820.html");
    return header;
}

/**
 * 返回Referer值带有10000的httpost
 * @param
 * @return
 */
function  getHttpPostCreditTwo(){

    var header = new HashMap();
    header.put("User-Agent", urls.USER_AGENT);
    header.put("Accept", urls.ACCEPT);
    header.put("Host", "3g.cib.com.cn");
    header.put("Origin", "https://3g.cib.com.cn");
    header.put("Referer", "https://3g.cib.com.cn/app/10000.html");
    return header;
}

/**
 * 返回Referer值带有50020的httpost
 * @param
 * @return
 */
function getHttpPostCreditThree(){

    var  header = new HashMap();
    header.put("User-Agent", urls.USER_AGENT);
    header.put("Accept", urls.ACCEPT);
    header.put("Host", "3g.cib.com.cn");
    header.put("Origin", "https://3g.cib.com.cn");
    header.put("Referer", "https://3g.cib.com.cn/app/50020.html");
    return header;
}

/**
 * 把分期描述里的数字提取出来或提取未出账单中的总页和当前页
 * @param des
 * @return
 */
function   getFen(des) {
    var list = new ArrayList();
    var r = Pattern.compile("\\d+");
    var m = r.matcher(des);
    while (m.find()) {
        list.add(Integer.parseInt(m.group()));
    }
    return list ;
}

function processDate(date) {
    var s = "";
    if (date !== null) {
        s = date.trim().replaceAll("-", "");
        s = s.replaceAll("：", "");
        s = s.replaceAll("/", "");
        s = s.replaceAll("年", "");
        s = s.replaceAll("月", "");
        s = s.replaceAll("日", "");
        if (s.length() < 8) {
            s = s + "01";
        }
    }
    return s;
}

// 根据中文币种生成英文币种
function   installmentTypeChange(type) {
    if (type.contains("账单")) {
        return "BILL";
    } else if (type.contains("现金")) {
        return "CASH";
    } else if (type.contains("消费") || type.contains("苹果") || type.contains("新兴业")) {
        return "CONSUME";
    } else {
        return "CONSUME";
    }
}